package com.chen.controller;

import com.chen.constant.MessageConstant;
import com.chen.entity.Result;
import com.chen.service.UserServiec;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.handler.MessageContext;

/**
 * @Author zhebie
 * @DATE 2021/9/21
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserServiec userServiec;

    //获取用户名
    @RequestMapping("/getUsername")
    public Result getUsername(){
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return new Result(true, MessageConstant.GET_USERNAME_SUCCESS,user.getUsername());
    }
}
